package com.css.apps.base.user.action.report;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import com.css.apps.base.user.service.UserCountGraphService;
import com.css.webbase.webwork.action.UserAction;

import net.sf.json.JSONArray;

@SuppressWarnings("serial")
public class DirRegistUserCount extends UserAction {

	private transient UserCountGraphService service = new UserCountGraphService();
	private List<String> headerTab = new ArrayList<>(), subTab = new ArrayList<>();
	private List<Object> headerData = new ArrayList<>(), subData = new ArrayList<>();
	private JSONArray axisX1 = new JSONArray(), axisX2 = new JSONArray();
	private int queryYear;
	
	@Override
	protected String userGo() {
		initTabHeader();
		initTabData();
		return SUCCESS;
	}

	private void initTabData() {
		if (queryYear == 0) {
			queryYear = Calendar.getInstance().get(Calendar.YEAR);
		}
		headerData = service.getHeaderRegistUserCountTabData(queryYear);
		subData = service.getSubRegistUserCountTabData(queryYear);
		Object[] x1 = new Object[12], x2 = new Object[12];
		for (int i = 0; i < x1.length; i++) {
			x1[i] = "-";
			x2[i] = "-";
		}
		for (int i = 0; i < headerData.size(); i++) {
			Object[] data = (Object[]) headerData.get(i);
			if (data != null) {
				int idx = Integer.valueOf((String) data[0]) - 1;
				x1[idx] = data[1];
			}
		}
		for (int i = 0; i < subData.size(); i++) {
			Object[] data = (Object[]) subData.get(i);
			if (data != null) {
				int idx = Integer.valueOf((String) data[0]) - 1;
				x2[idx] = data[1];
			}
		}
		axisX1 = JSONArray.fromObject(x1);
		axisX2 = JSONArray.fromObject(x2);
	}

	private void initTabHeader() {
		headerTab.add("月份");
		headerTab.add("注册总数");
		subTab.add("月份");
		subTab.add("注册总数");
	}

	public List<String> getHeaderTab() {
		return headerTab;
	}

	public void setHeaderTab(List<String> headerTab) {
		this.headerTab = headerTab;
	}

	public List<String> getSubTab() {
		return subTab;
	}

	public void setSubTab(List<String> subTab) {
		this.subTab = subTab;
	}

	public List<Object> getHeaderData() {
		return headerData;
	}

	public void setHeaderData(List<Object> headerData) {
		this.headerData = headerData;
	}

	public List<Object> getSubData() {
		return subData;
	}

	public void setSubData(List<Object> subData) {
		this.subData = subData;
	}

	public int getQueryYear() {
		return queryYear;
	}

	public void setQueryYear(int queryYear) {
		this.queryYear = queryYear;
	}

	public JSONArray getAxisX1() {
		return axisX1;
	}

	public void setAxisX1(JSONArray axisX1) {
		this.axisX1 = axisX1;
	}

	public JSONArray getAxisX2() {
		return axisX2;
	}

	public void setAxisX2(JSONArray axisX2) {
		this.axisX2 = axisX2;
	}

}
